#include "MutexLock.hpp"

#include <stdio.h>
namespace xkk
{

MutexLock::MutexLock()
{
    if(pthread_mutex_init(&_mutex,nullptr)){
        perror("pthread_mutex_init");
    }
}

MutexLock::~MutexLock()
{
    if(pthread_mutex_destroy(&_mutex)){
        perror("pthread_mutex_destroy");
    }
}

void MutexLock::lock()
{
    if(pthread_mutex_lock(&_mutex)){
        perror("pthread_mutex_lock");
    }
    _isLocking=true;
}

void MutexLock::unlock()
{
    if(pthread_mutex_unlock(&_mutex)){
        perror("pthread_mutex_unlock");
    }
    _isLocking=false;
}
}//end of namespace xkk
